<template>
  <div class="app-container">
    <el-page-header content="网络安全文章管理" @back="goBack" />
    <el-divider />
    <div style="width: 20vw;">
      <el-input v-model="params.title" placeholder="请标题"></el-input>
      <el-button type="primary" icon="el-icon-search" @click="getData">搜索</el-button>
    </div>
    <el-divider />
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="ID">
        <template v-slot="scope">
          <span> {{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="标题">
        <template v-slot="scope">
          <span> {{ scope.row.title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="内容">
        <template v-slot="scope">
          <span> {{ scope.row.content }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建时间" width="95">
        <template v-slot="scope">
          <span>{{ scope.row.createdAt }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="更新时间" width="95">
        <template v-slot="scope">
          <span>{{ scope.row.updatedAt }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        fixed="right"
        label="操作"
        width="150"
      >
        <template v-slot="scope">
          <el-popconfirm title="确认编辑吗？" @confirm="openEdit(scope.row)">
            <el-button slot="reference" size="small">编辑</el-button>
          </el-popconfirm>
          <el-popconfirm title="确认删除吗？" icon-color="red" @confirm="handleDelete(scope.row)">
            <el-button slot="reference" size="small">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-divider />
  </div>
</template>

<script>

import { delComm, getListComm } from '@/api/comm'
import { successMsg } from '@/utils/comm'

export default {
  data() {
    return {
      module: 'blog',
      list: null,
      listLoading: true,
      params: {
      }
    }
  },
  created() {
    this.getData()
  },
  methods: {
    openEdit(row) {
      this.$router.push('/blog/edit/' + row.id)
    },
    handleDelete(row) {
      delComm(this.module, row.id).then(response => {
        successMsg()
        this.getData()
      })
    },
    openAdd() {
      this.$router.push('/blog/add')
    },
    handleSizeChange(val) {
      this.params.pageSize = val
      this.getData()
    },
    handleCurrentChange(val) {
      this.params.pageNum = val
      this.getData()
    },
    getData() {
      this.listLoading = true
      getListComm(this.module, this.params).then(response => {
        this.list = response.data
        this.listLoading = false
      })
    },
    goBack() {
      this.$router.push('/dashboard')
    }
  }
}
</script>
<style>
.el-select {
  width: 5vw;
}

</style>

